import TableData from "@/components/commonPublic/el-table"; //主页面列表
import publicForm from "@/components/PCManage/fromCom.vue"; //弹框form
import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
import formJs from "./regexDetail.js"; //新增弹框配置
import TableLyout from '@/components/commonPublic/tableLyout.vue'
import tree from "@/components/PCManage/tree"; //左侧机构树
import CustomDialogs from "@/components/PCManage/reboundData/index.vue";
import CustomDialog from "@/components/PCManage/reboundUnqualifiedData/index.vue";

import {
    getConcreteChecksamplePageList, //列表
    submitConcreteCheckSample, //提交
    revokeConcreteCheckSample, //删除
    getUserCompanyTreeList
} from "@/api/request.js";

export default {
    name: "reboundUnqualifiedData",
    data() {
        return {
            name: "reboundUnqualifiedData",
            defaultProps: {
                children: "children",
                label: "fShortname",
            },
            treeText: {
                companyId: null,
                userId: null,
            },
            companyTree: "", //所有数据
            treeData: [], //左侧树状图数据
            // 机构树
            highlightBd: true, //左侧机构树停留背景色
            treelength: false, //左侧树显示隐藏
            showName: "未选择公司",
            checkData: [], //树状图默认选中id
            isLock: false,
            loading: false,
            btnObj:formJs.btnObj, //按钮
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            radio: "待办",
            // 列表
            getList: {
                startDates: "", // 开始时间
                endDates: "", // 截至时间
                modelType: "2", // 0待办 1已办 2查询
                userId: "", // 查询待办或已办时传 列表页查询不传
                fCompanyid: "",
                page: 1, // 当前页码
                pageSize: 20, // 每页显示条数
                keyType: "",
                timeDates: null
            },
            isShow: false, //是否显示弹框
            biheIsShow: false,
            statusNum: null, //点击那个按钮
            dataFid: null, //列表详情id
            currentRow: null, //列表详情
            tableData: [],
            dialogTitle: null,

        };
    },
    components: {
        TableLyout,
        publicForm,
        TableData,
        tree,
        elBreadcrumb,
        CustomDialogs, //记录及报告
        CustomDialog, //闭合
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
        if (JSON.parse(sessionStorage.getItem("engineerList"))) {
            var id = JSON.parse(
                sessionStorage.getItem("engineerList")
            );
            this.checkData = [id.fCompanyid];
        }
        // this.getDate();
        this.table_config.operation.cols = [{
            prop: "fCloseoperation",
            type: "primary",
            handleRow: this.handleRow,
        },];

        this.table_config.operation["specialClass"] = function (rowData) {
            var color = null;

            if (rowData == "未闭合") {
                color = "red !important";
            } else if (rowData == "已闭合") {
                color = "green !important";
            } else if (rowData == "无需闭合") {
                color = "#000 !important";
            } else {
                color = "#409eff !important";
            }
            return color;
        };
        this.btnRole(this.name)
        this.getTree();
    },
    methods: {
        refreshList() { //刷新列表

            this.$nextTick(() => {
                this.yj_searchForm(this.getList);
            })
        },

        closeDialog() {
            this.isShow = false;
        },
        bihecloseDialog() {
            this.biheIsShow = false;
        },
        Print(num) {
            if (num == 1) {
              window.open(
                "http://1.14.19.236:8054/concreteScreen/App/upload/getExcelByConcreteSample.do?fId=" +
                this.equipmentDetailId
              );
            } else if (num == 2) {
              window.open(
                "http://1.14.19.236:8054/concreteScreen/App/upload/getExcelByConcreteSampleCode.do?fId=" +
                this.equipmentDetailId
              );
            }
          },
        // 左侧树结构
        getTree() {
            this.treeText.companyId = this.userInfo.companyId;
            this.treeText.userId = this.userInfo.userId;
            getUserCompanyTreeList(this.treeText)
                .then((res) => {
                    if (res.errcode == 0) {
                        var companyTree = res.data.userCompanyTreeList;
                        this.treeData = this.commonJs.tranListToTreeData(companyTree);
                        if (this.treeData[0].children == undefined) {
                            this.treelength = false; //左侧组织机构是否显示
                        } else {
                            this.treelength = true;
                        }

                        if (this.checkData[0]) {
                            this.showName = JSON.parse(
                                sessionStorage.getItem("engineerList")
                            ).fShortname;
                            this.getList.fCompanyid = this.checkData[0];
                        } else {
                            this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
                            this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
                            this.checkData[0] = this.treeData[0].fCompanyid;
                        }

                        this.yj_searchForm(this.getList); // 调用主页面列表接口
                        // 列表
                    } else {
                        this.$message.error(res.msg);
                        return false;
                    }
                })
                .catch(() => {
                    return false;
                });
        },
        // 点击左侧机构树
        handleNodeClick(data) {
            this.showName = data.fShortname; //顶部显示机构名
            this.getList.fCompanyid = data.fCompanyid;
            this.getList.page = 1;
            this.getList.pageSize = 20;
            this.yj_searchForm(this.getList);
        },
        handleRow() { },
        btnRole(name) {
            if (this.userInfo.userId != 'System') {
                var btnList = [];
                var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
                if (ModuleList.length > 0) {
                    ModuleList.map((item) => {
                        if (item.fEncode == name) {
                            btnList = item.modulebuttonList;
                        }
                    });
                    btnList.map(item => {
                        item['disabled'] = false
                    })
                    this.btnObj = btnList
                }
            } else {
                this.btnObj = formJs.btnObj
            }
            this.btnObj = formJs.btnObj
        },
        getBtnName(name, status) {
            this.statusNum = status
            this.yj_edit(status)
        },
        // 新增/编辑
        yj_edit(num) {
            if (this.dataFid != null) {
                if (num == 1) {
                    window.open(
                      "http://1.14.19.236:8054/concreteScreen/App/upload/getExcelByConcreteSample.do?fId=" +
                      this.dataFid
                    );
                  } else if (num == 2) {
                    window.open(
                      "http://1.14.19.236:8054/concreteScreen/App/upload/getExcelByConcreteSampleCode.do?fId=" +
                      this.dataFid
                    );
                  }
            } else {
                this.$message.warning("请先选择需要打印的数据");

            }

            
         
        },
        editText() {
            this.isShow = true;
        },
        // 撤销
        yj_revoke() {
            if (this.currentRow != null) {
                if (this.dataFid != "" && this.dataFid != null) {
                    this.$confirm("是否继续撤销?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    })
                        .then(() => {
                            this.isLock = true
                            this.loading = true;
                            revokeConcreteCheckSample({
                                fId: this.dataFid,
                                userId: this.userInfo.userId, //当前登录人id
                                userName: this.userInfo.realName //当前登录人姓名
                            })
                                .then((res) => {
                                    if (res.errcode == 0) {
                                        this.loading = false;
                                        this.dataFid = null
                                        this.isLock = false
                                        this.yj_searchForm(this.getList);
                                        this.$message.success("撤销成功");
                                    } else if (res.errcode == -2) {
                                        this.loading = false;
                                        this.dataFid = null
                                        this.isLock = false
                                        this.yj_searchForm(this.getList);
                                        this.$message.warning(res.msg);
                                    } else {
                                        this.isLock = false
                                        this.$message.error("撤销失败", res.msg);
                                        this.loading = false;
                                        return false;
                                    }
                                })
                                .catch(() => {
                                    this.loading = false;
                                    console.log("撤销失败");
                                });
                        })
                        .catch(() => {
                            this.$message("取消撤销");
                        });
                } else {
                    return this.$message.error("请先选择需要撤销的数据");
                }
            }
        },

        // 查看
        // 点击查看
        yj_viewForm(row, label) {
            if (label == 1) { //闭合
                console.log(row);
                this.currentRow = row;
                this.statusNum = 7;
                this.biheIsShow = true;

            } else {
                if (label == "报告编号") {
                    this.currentRow = row;
                    this.statusNum = 7
                    this.isShow = true;

                } else if (label == "任务编号") {
                    this.currentRow = row;
                    this.statusNum = 8
                    this.isShow = true;
                }
            }

        },
        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val
            this.dataFid = val.fId;
        },

        // 获取列表数据
        
        yj_searchForm(data) {
            
            this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
            console.log(88899,data,this.userInfo);
            // window.sessionStorage.setItem(
            //     "GxBack-reboundStrengthManage_getList",
            //     JSON.stringify(data)
            // );
            var obj = {
                // startDates: data.startDates, // 开始时间
                // endDates: data.endDates, // 截至时间
                modelType: "3", // 0待办 1已办 2查询
                userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
                fCompanyid: data.fCompanyid,
                page: data.page, // 当前页码
                pageSize: data.pageSize, // 每页显示条数
            }
            this.loading = true;
            getConcreteChecksamplePageList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        var that = this;
                        that.loading = false;
                        that.tableData = res.data.checkConcretesampleList.list;
                        that.queryCriteriaData = res.data.checkConcretesampleList;
                    } else {
                        this.$message.error("列表", res.msg);
                        this.loading = false;
                    }
                })
                .catch(() => {
                    this.loading = false;
                    console.log("获取列表数据接口报错");
                });
        },
        // 提交
        yj_submit(row) {
            if (row.fId != "" && row.fId != null && row.fId != undefined) {
                if (row.fStatus == "编辑中") {
                    this.$confirm("是否继续提交?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    })
                        .then(() => {
                            this.loading = true;
                            submitConcreteCheckSample({
                                fId: row.fId,
                            })
                                .then((res) => {
                                    if (res.errcode == 0) {
                                        this.loading = false;
                                        this.yj_searchForm(this.getList);
                                        this.$message.success("提交成功");
                                    } else {
                                        this.$message.error("提交失败", res.msg);
                                        this.loading = false;
                                    }
                                })
                                .catch(() => {
                                    console.log("提交失败");
                                    this.loading = false;
                                });
                        })
                        .catch(() => {
                            this.$message("取消提交");
                        });
                } else {
                    return this.$message.warning('请选择信息状态为"编辑中"的数据！');
                }
            } else {
                return this.$message.warning("请先选择需要提交的数据");
            }
        },

        selectTime(e) {
            if (e[0] != "" && e[1] != "") {
                this.getList.startDates = e[0]; // 开始时间
                this.getList.endDates = e[1]; // 截至时间
            } else {
                this.getList.startDates = ""; // 开始时间
                this.getList.endDates = ""; // 截至时间
            }
            this.getList.timeDates = [e[0], e[1]]

            this.yj_searchForm(this.getList);
        },
        getDate() {

            this.getTree();

            if (JSON.parse(sessionStorage.getItem("GxBack-reboundStrengthManage_getList"))) {
                var data = JSON.parse(sessionStorage.getItem("GxBack-reboundStrengthManage_getList"));
                // this.getList.timeDates = [data.startDates, data.endDates]

                this.getList = {
                    fCompanyid: data.fCompanyid, //左侧选中组织机构id
                    page: 1, //当前页码
                    pageSize: 20, //每页显示条数
                    userId: this.userInfo.userId, //查询待办或已办时传 列表页查询不传
                    modelType: 2, //0-待办 1-已办 传2 表示列表页查询
                    startDates: data.startDates, //进场开始时间
                    endDates: data.endDates, //进场结束时间
                    keyType: "",
                    timeDates: [data.startDates, data.endDates],
                };
            } else {
                this.getList.startDates = this.common.getDay(-6); // 开始时间
                this.getList.endDates = this.common.getDay(0); // 截至时间
                this.getList.timeDates = [this.getList.startDates, this.getList.endDates]


            }
            // this.yj_searchForm(this.getList);
        },

    },
};